package com.iemes.controller.warehouse;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Map;

import javax.inject.Inject;
import javax.servlet.http.HttpServletRequest;

import org.apache.shiro.SecurityUtils;
import org.apache.shiro.session.Session;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import com.iemes.annotation.SystemLog;
import com.iemes.controller.index.BaseController;
import com.iemes.entity.AnalyzeformFormMap;
import com.iemes.entity.EnterstorageFormMap;
import com.iemes.entity.LabelMaterialFormMap;
import com.iemes.entity.MaterFromMap;
import com.iemes.entity.OrderFormMap;
import com.iemes.entity.UserFormMap;
import com.iemes.mapper.shape.ShapeMapper;
import com.iemes.mapper.warehouse.EnterstorageMapper;
import com.iemes.mapper.warehouse.LabelMaterialMapper;
import com.iemes.plugin.PageView;
import com.iemes.util.Common;

@RequestMapping("/labelmaterial_form/")
@Controller
public class LabelMaterial_FormController extends BaseController {

	@Inject
	private LabelMaterialMapper labelMaterialMapper;
	
	// 查看物料信息表，显示按钮。
	@RequestMapping("labelmaterial_form")
	public String analyze_form(Model model) {
		model.addAttribute("res", findByRes());
		return Common.BACKGROUND_PATH + "/warehouse/labelmaterial_form_list";
	}
	
	// 物料信息表分页
	@ResponseBody
	@RequestMapping("labelmaterial_form_findByPage")
	public PageView findByPage(String pageNow, String pageSize) throws Exception {
		LabelMaterialFormMap labelMaterialFormMap = getFormMap(LabelMaterialFormMap.class);
		List<Map<String, Object>> labelMaterial = labelMaterialMapper.getAll(labelMaterialFormMap);
		LuogicPaging(pageNow, pageSize, labelMaterial);
		return pageView;
	}
	
	// 编辑物料信息表
	@RequestMapping("labelmaterial_form_edit")
	public String editUI(Model model) throws Exception {
		String id = getPara("id");
		if(Common.isNotEmpty(id)){
			//根据id获得物料信息表
			LabelMaterialFormMap material=labelMaterialMapper.getById(id);
			model.addAttribute("material",material);
		}
		return Common.BACKGROUND_PATH + "/warehouse/labelmaterial_form_edit";
	}
	
	// 修改物料信息表
	@ResponseBody
	@RequestMapping(value = "labelmaterial_form_editEntity")
	@Transactional(readOnly=false)//需要事务操作必须加入此注解
	@SystemLog(module = "物料信息表", methods = "查看物料信息表-修改物料信息表") // 凡需要处理业务逻辑的.都需要记录操作日志
	public String editEntity() throws Exception {
		LabelMaterialFormMap labelMaterialFormMap = getFormMap(LabelMaterialFormMap.class);
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		Date date = new Date();
		Session session = SecurityUtils.getSubject().getSession();
		labelMaterialFormMap.put("date", sdf.format(date));
		labelMaterialFormMap.put("fillPeopleId", session.getAttribute("userSessionId"));
		baseMapper.editEntity(labelMaterialFormMap);
		return "success";
	}
}









